/****

    activequant - activestocks.eu

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License along
    with this program; if not, write to the Free Software Foundation, Inc.,
    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

	
	contact  : contact@activestocks.eu
    homepage : http://www.activestocks.eu

 ****/
package org.activequant.calendar;

/**
 * A singleton factory creating calendars based on calendar settings.<br/>
 * Holds the following associated variables:
 * <ul>
 * <li>factory(CalendarFactory)</li>
 * </ul>
 * <b>History:</b><br>
 * - [May 30, 2008] Created (mark)<br>
 * 
 * @author mark
 */
public class CalendarFactory {
	/**
	 * private static final CalendarFactory factory = new CalendarFactory();
	 */
	private static final CalendarFactory factory = new CalendarFactory();

	/**
	 * Get an instance of this factory.<br/>
	 * returns the associated factory(CalendarFactory)
	 * @return the instance of this factory.
	 */
	public static CalendarFactory getInstance() {
		return factory;
	}

	/**
	 * Get an exchange calendar given the exchange calendar settings and holiday calendar.<br/>
	 * Creates and returns a new ExchangeCalendar (implements IExchangeCalendar) using the given settings(IExchangeCalendarSettings) to set its associated
	 * exchange(Exchange), timeZone(TimeZone), openingMillis(long) and closingMillis(long).<br/>
	 * Sets its associated holidays(IHolidayCalendar) with the given holidays(IHolidayCalendar). The timeZone(TimeZone) in the given holidays(IHolidayCalendar) must match the one
	 * in the given settings(IExchangeCalendarSettings).
	 * @param settings
	 *            the exchange calendar settings for the exchange
	 * @param holidays
	 *            the holiday calendar for the exchange
	 * @return the exchange calendar
	 */
	public synchronized IExchangeCalendar getCalendar(final IExchangeCalendarSettings settings, final IHolidayCalendar holidays) {
		final ExchangeCalendar exchangeCalendar = new ExchangeCalendar(settings, holidays);
		return exchangeCalendar;
	}

	/**
	 * Get a holiday calendar given the holiday calendar settings.<br/>
	 * Creates and returns a new HolidayCalendar (extends ArrayList&lt;HolidayCalendarEntry&gt; implements IHolidayCalendar) using the given settings(IHolidayCalendarSettings)
	 * to set its associated timeZone(TimeZone) and HolidayCalendarEntry elements.<br/>
	 * It also validates that the timeZone(TimeZone) of each HolidayCalendarEntry element matches its associated timeZone(TimeZone).
	 * @param settings
	 *            the holiday calendar settings to use.
	 * 
	 * @return the holiday calendar.
	 */
	public synchronized IHolidayCalendar getCalendar(final IHolidayCalendarSettings settings) {
		return new HolidayCalendar(settings);
	}
}
